/*    */ package com.newcrm.webapi.sub;
/*    */ 
/*    */ import com.newcrm.bean.User;
/*    */ import com.newcrm.db.UserEmailManager;
/*    */ import com.newcrm.exception.DBException;
/*    */ import com.newcrm.exception.NotFoundException;
/*    */ import com.newcrm.util.EmailUtil;
/*    */ import com.newcrm.util.Util;
/*    */ import com.newcrm.webapi.AbstractAction;
/*    */ import com.newcrm.webapi.AbstractHttpServlet;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.SQLException;
/*    */ import javax.servlet.ServletException;
/*    */ import javax.servlet.http.HttpServletRequest;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.commons.mail.EmailException;
/*    */ import org.apache.log4j.Logger;
/*    */ 
/*    */ public class CheckEmailSetting extends AbstractAction
/*    */ {
/* 26 */   private static Logger logger = Logger.getLogger(CheckEmailSetting.class
/* 27 */     .getName());
/*    */ 
/* 29 */   private String id = null;
/*    */ 
/*    */   public CheckEmailSetting(AbstractHttpServlet servlet, String id) {
/* 32 */     super(servlet);
/* 33 */     this.id = id;
/*    */   }
/*    */ 
/*    */   public CheckEmailSetting(AbstractHttpServlet servlet) {
/* 37 */     super(servlet);
/*    */   }
/*    */ 
/*    */   public void parse(HttpServletRequest request, HttpServletResponse response)
/*    */     throws IOException, ServletException, NotFoundException
/*    */   {
/* 43 */     response.setContentType("text/html;charset=utf-8");
/* 44 */     PrintWriter out = response.getWriter();
/* 45 */     JSONObject jsonObject = new JSONObject();
/*    */ 
/* 47 */     User user = super.getLoginUser(request);
/* 48 */     if ((!user.userId.equals(this.id)) && (!user.isAdmin)) {
/* 49 */       jsonObject.put("error", "1");
/* 50 */       out.println(jsonObject);
/* 51 */       out.flush();
/* 52 */       out.close();
/* 53 */       return;
/*    */     }
/*    */ 
/* 56 */     String host = Util.getURLParameter(request.getParameter("host"));
/* 57 */     int port = Util.getURLIntParameter(request.getParameter("port"));
/* 58 */     String username = 
/* 59 */       Util.getURLParameter(request.getParameter("username"));
/*    */ 
/* 61 */     String password = 
/* 62 */       Util.getURLParameter(request.getParameter("password"));
/* 63 */     boolean isSSL = "1".equals(Util.getURLParameter(request
/* 64 */       .getParameter("isSSL")));
/* 65 */     String emailAddress = Util.getURLParameter(request
/* 66 */       .getParameter("emailAddress"));
/* 67 */     String sign = Util.getURLParameter(request.getParameter("sign"));
/*    */     try
/*    */     {
/* 70 */       EmailUtil.checkEmailSetting(host, port, username, password, isSSL, 
/* 71 */         emailAddress);
/*    */ 
/* 73 */       UserEmailManager manager = new UserEmailManager();
/*    */       try
/*    */       {
/* 76 */         int result = manager.update(this.id, host, port, username, 
/* 77 */           password, isSSL, emailAddress, sign);
/* 78 */         if (result == 0)
/* 79 */           manager.add(this.id, host, port, username, password, isSSL, 
/* 80 */             emailAddress, sign);
/*    */       }
/*    */       catch (SQLException e) {
/* 83 */         logger.warn("update user email setting failed", e);
/*    */       } catch (DBException e) {
/* 85 */         logger.warn("update user email setting failed", e);
/*    */       }
/*    */ 
/* 88 */       jsonObject.put("error", "0");
/*    */     } catch (EmailException e) {
/* 90 */       jsonObject.put("error", "1");
/* 91 */       jsonObject.put("errorMsg", e.getMessage());
/* 92 */       logger.warn("check email setting failed", e);
/*    */     }
/* 94 */     out.println(jsonObject);
/* 95 */     out.flush();
/* 96 */     out.close();
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.webapi.sub.CheckEmailSetting
 * JD-Core Version:    0.6.1
 */